/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file           : main.h
 * @brief          : Header for main.c file.
 *                   This file contains the common defines of the application.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2023 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "Data_uart.h"
#include "inv_mpu.h"
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

    typedef struct
    {
        int16_t encoder;
        int16_t last_encoder;
        int16_t encoder_is_init;
        int16_t round_cnt;
        int16_t encoder_offset;
        int16_t angle_offset;
        float total_encoder;
        int16_t angle;
        int16_t l_angle;
    } motor_angle;

    typedef struct
    {
        int target;
        int data_now;
        int data_before;
        int integral;
        int last_target;
    } PID_variables;

    typedef struct
    {
        float kp;
        float ki;
        float kd;
        float kf;
    } PID_parameter;

    typedef enum
    {
        SPEED = 0,
        FBK,
        CURRENT,
        ARR_SPACE
    } signal;
    typedef enum
    {
        P = 0,
        R,
        Y,
        mpu_signal_array_space
    } mpu_signal_array;
    // arr that show whether motor is init
    typedef enum
    {
        FWL_INIT = 0X01,
        FWR_INIT = 0X02,
        TP_INIT = 0X04,
        PITCH_INIT = 0X08,
        YAW_INIT = 0X10,
        M_ALL_INIT = 0X1F,
    } MOTOR_INIT;
//==========================MOTOR_IN_ALL
#define M_NUM 5
#define M_RX_ARR_SPACE 8
#define M_RX_ARR_ENC_H 0
#define M_RX_ARR_ENC_L 1
#define M_RX_ARR_SPEED_H 2
#define M_RX_ARR_SPEED_L 3
//==========================FWL
#define FWL_ID 0             // id
#define MAX_FWL_OUTPUT 16000 // the max signal that send to the motor
#define FWL_FILTER FWL_ID    // filter id 0~4
#define FWL_TX_ID 0X200      // transmit id of the motor
#define FWL_TX_DATA_H 2      // higher order byte
#define FWL_TX_DATA_L 3      // lower order byte
#define FWL_RX_ID 0X202      // recive id
//==========================FWR
#define FWR_ID 1
#define MAX_FWR_OUTPUT 16300
#define FWR_FILTER FWR_ID
#define FWR_TX_ID 0x200
#define FWR_TX_DATA_H 4
#define FWR_TX_DATA_L 5
#define FWR_RX_ID 0X203
//==========================TP
#define TP_ID 2
#define MAX_TP_OUTPUT 9900
#define TP_FILTER TP_ID
#define TP_TX_ID 0x200
#define TP_TX_DATA_H 0
#define TP_TX_DATA_L 1
#define TP_RX_ID 0X201
//==========================PITCH
#define PITCH_ID 3
#define MAX_PITCH_OUTPUT 29900
#define PITCH_FILTER PITCH_ID
#define PITCH_TX_ID 0x1ff
#define PITCH_TX_DATA_H 2
#define PITCH_TX_DATA_L 3
#define PITCH_RX_ID 0x206
//==========================YAW
#define YAW_ID 4
#define MAX_YAW_OUTPUT 29900
#define YAW_FILTER YAW_ID
#define YAW_TX_ID 0x2ff
#define YAW_TX_DATA_H 0
#define YAW_TX_DATA_L 1
#define YAW_RX_ID 0X209
    // UART ć˛çşżé˘č˛
    typedef enum
    {
        RED = 0,
        BLUE,
        YELLOW,
        GREEN,
        COLOR_ARR_SPACE
    } COLOR;

// éĽć§ćć
#define UP 1
#define MID 3
#define DOWN 2
#define L_S 1
#define R_S 0

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
